package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.PickingPurchase;
import com.pureut.storage.domain.PickingRestDetail;
import com.pureut.storage.dto.PickingRestDetailDto;
import com.pureut.storage.mapper.PickingPurchaseMapper;
import com.pureut.storage.mapper.PickingRestDetailMapper;
import com.pureut.storage.service.PickingPurchaseService;
import com.pureut.storage.service.PickingRestDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: YSL
 * @Date: 2023/1/19 17:34
 * @Desc: 其他出库 实现层
 */
@Service
public class PickingRestDetailServiceImpl extends ServiceImpl<PickingRestDetailMapper, PickingRestDetail> implements PickingRestDetailService {

    /**
     * 其他出库明细 mapper
     */
    @Resource
    PickingRestDetailMapper pickingRestDetailMapper;


    /**
     * 查询其他出库明细列表
     * @param docNum
     * @return
     */
    @Override
    public List<PickingRestDetailDto> getRestList(String docNum) {

        // 其他出库明细物料状态
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_rest_detail_status");
        Map<String, String> materialMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 其他出库明细网型
        List<SysDictData> meshTypeArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> meshTypeMap = meshTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 其他出库明细铺网类型
        List<SysDictData> layingTypeArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> layingTypeMap = layingTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 明细List
        List<PickingRestDetailDto> restList = pickingRestDetailMapper.getRestList(docNum);
        for (PickingRestDetailDto pickingRestDetailDto : restList){
            // 物料状态
            pickingRestDetailDto.setMaterialStatusDict(materialMap.get(String.valueOf(pickingRestDetailDto.getMaterialStatus())));

            // 网型状态
            pickingRestDetailDto.setMeshTypeDict(meshTypeMap.get(String.valueOf(pickingRestDetailDto.getMeshType())));

            // 铺网类型状态
            pickingRestDetailDto.setTypeOfLayingDict(layingTypeMap.get(String.valueOf(pickingRestDetailDto.getTypeOfLaying())));
        }


        return restList;
    }
}
